package 力扣日常刷题.木22一月.第08天0116;

/**
 * @author 帅小伙
 * @date 2022/1/16
 * @description
 */
public class Demo04枚举中等统计作战单位数 {


    public int numTeams(int[] rating) {
        int n = rating.length;
        int ans = 0;

        for (int j = 0; j < n; j++) {
            int il = 0,im = 0;
            int kl = 0,km = 0;
            for (int i = 0; i < j; i++) {
                if(rating[i] <rating[j])il++;
                if(rating[i] > rating[j])im++;
            }

            for (int k = j+1; k < n; k++) {
                if(rating[k] <rating[j])kl++;
                if(rating[k] > rating[j])km++;
            }
            ans = ans+(il*km)+(im*kl);
        }

        return ans;
    }

}
